<?php

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\ApiController;
use App\Models\Hospital;
use App\Models\UserBase;
use Illuminate\Http\Request;

class HospitalController extends ApiController
{
    public function doctors(Request $request)
    {

        $this->validate($request, [
            'hospital_id' => 'integer',
        ]);

        $user = \Auth::user();
        $hospital_id = $request->input('hospital_id');
        if (!$hospital_id) {
            $hospital_id = $user->hospital_id;
        }
        $hospital_ids[] = $hospital_id;

        $user_type = $user->type;
        $intype = [];
        switch ($user_type) {
            case 0:
                $intype = ['2', '3', '4'];
                break;
            case 2:
                $intype = ['2'];
                break;
            case 3:
                $intype = ['2', '3'];
                break;
            case 4:
                $intype = ['2', '3', '4'];
                break;
        }

        $doctor_list = UserBase::where('hospital_id', $hospital_id)
            ->select('id', 'name')
            ->orderBy('id', 'desc')
            ->whereIn('type', $intype)
            ->get()
            ->toArray();

        return $this->response($doctor_list);
    }

}
